#!/bin/bash

# This script runs the compilation/compile-fail tests to make sure the library 
# behaves as required syntactically. The actual functionality tests are built 
# by the CMake build system.
# TODO: Find out if this can be integrated into the CMake build?

CFLAGS="-I/opt/local/include -I../ -DBOUNDS_CHECK -g" 
WFLAGS="-Werror -Wall -Wshadow -Wconversion"
SRCS="../warray/*.cpp"
OUTDIR="/var/tmp/warray"

mkdir -p $OUTDIR

OBJS=
for i in $SRCS
do
	j=$OUTDIR/`basename ${i/.cpp/.o}`
	OBJS="$OBJS $j"
	g++ $CFLAGS $WFLAGS $i -c -o $j
done

# Syntax tests (correct syntax)
mkdir -p $OUTDIR/syntax
for i in syntax/*.cpp
do
	if g++ $CFLAGS $WFLAGS $OBJS $i -o $OUTDIR/${i/.cpp/}; then
		printf "%-60s: PASS\n" "$i compile"
	else
		printf "%-60s: FAIL\n" "$i compile"
	fi
done

# Syntax tests (incorrect syntax)
mkdir -p $OUTDIR/errors
for i in errors/*.cpp
do
	if g++ $CFLAGS $OBJS $i -o $OUTDIR/${i/.cpp/} 1>/dev/null 2>/dev/null; then
		printf "%-60s: FAIL\n" "$i compile"
	else
		printf "%-60s: PASS\n" "$i compile"
	fi
done
